#include "MoveVertexCmd.h"

MoveVertexCmd::MoveVertexCmd(UMLLine* line, UMLLine::size_type vertex)
:	_executed(false),
	_target(line),
	_vertex(vertex),
	_pos(line->vertex(vertex))
{
}

void MoveVertexCmd::execute()
{
	if (!_executed)
		_oldPos = _target->vertex(_vertex);

	_target->setVertex(_vertex, _pos);

	_executed = true;
}

void MoveVertexCmd::unexecute()
{
	if (!_executed)
		return;

	_target->setVertex(_vertex, _oldPos);

	_executed = false;
}

bool MoveVertexCmd::useful() const
{
	return (_executed) ?
		(_oldPos != _pos) :
		(_target->vertex(_vertex) != _pos);
}

const char* MoveVertexCmd::name() const
{
	return "MoveVertexCmd";
}

